﻿@using DormMS.Model.Enum
@{
    Layout = null;
}

<h3>降拼活动</h3>
<div class="panel panel-default" ng-controller="SpecialTopicController" ng-class="{ 'whirl standard': isLoading}">
    <div class="panel-heading">
        <div class="form-inline ng-pristine ng-valid">
            <div class="form-group">
                <input placeholder="关键字" class="form-control" type="text" ng-model="Keywords">
                <button type="submit" class="btn btn-labeled btn-primary" ng-click="tableParams.$params.page = 1;tableParams.reload()">
                    <span class="btn-label">
                        <em class="fa fa-search"></em>
                    </span>搜索
                </button>
            </div>
            <div class="form-group">
                <button type="submit" class="btn btn-labeled btn-success" ng-click="edit(0)">

                    <span class="btn-label">
                        <em class="fa fa-plus"></em>
                    </span>新增
                </button>
            </div>
        </div>
    </div>
    <div class="panel-body">
        <div class="table-responsive">
            <table ng-table="tableParams" class="table table-striped table-bproducted table-hover">
                @*<colgroup>
                        <col style="width: 15%" />
                        <col style="width: 20%" />
                        <col style="width: 20%" />
                        <col style="width: 15%" />
                        <col style="width: 15%" />
                        <col style="width: 15%" />
                    </colgroup>*@
                <tbody>
                    <tr ng-repeat="model in $data">
                        <td data-title="'降拼活动ID'" class="text-center">{{model.DropGroupID}}</td>
                        <td data-title="'降拼活动名称'" class="text-center">{{model.Title}}</td>
                        <td data-title="'起始价'" class="text-center">{{model.StartingPrice}}</td>
                        <td data-title="'底价'" class="text-center">{{model.FloorPrice}}</td>
                        <td data-title="'每次降价金额'" class="text-center">{{model.DropPrice}}</td>
                        <td data-title="'团长是否免单'" class="text-center">{{model.IsFree==0?"否":"是"}}</td>
                        <td data-title="'开团人数'" class="text-center">{{model.TeamCount}}</td>
                        <td data-title="'活动状态'" class="text-center">{{model.State==0?"上架":"下架"}}</td>
                        <td data-title="'时间截至'" class="text-center">{{model.BeginTime +'至'+ model.EndTime}}</td>
                        <td data-title="'操作'" nowrap="nowrap" class="text-center">
                            <button type="button" ng-click="updateStatus($index,model.DropGroupID,1)" class="btn btn-sm btn-warning" ng-show="model.State==0" title="下架">
                                <em class="fa fa-hand-o-down"></em>
                            </button>
                            <button type="button" ng-click="updateStatus($index,model.DropGroupID,0)" class="btn btn-sm btn-warning" ng-show="model.State==1" title="上架">
                                <em class="fa fa-hand-o-up"></em>
                            </button>
                            <button type="button" ng-click="remove($index,model.DropGroupID)" class="btn btn-sm btn-danger" ng-show="model.TeamCount==0&&model.State!=0" title="删除">
                                <em class="fa fa-trash-o"></em>
                            </button>
                            <button type="button" ng-click="edit(model.DropGroupID)" class="btn btn-sm btn-info" title="编辑">
                                <em class="fa fa-edit"></em>
                            </button>
                            <button type="button" ng-click="gogroupheadlist(model.DropGroupID)" class="btn btn-sm btn-warning" ng-show="model.TeamCount>0" title="活动团">
                                <em class="fa fa-list"></em>
                            </button>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <script type="text/ng-template" id="modalDialogId">
        <div class="ngdialog-message text-center">
            <h3>确定要删除吗?</h3>
            <p>删除后不可恢复!</p>
            <br />
            <button type="button" ng-click="confirm()" class="btn btn-primary mr">确认</button>
            <button type="button" ng-click="closeThisDialog('button')" class="btn btn-default">取消</button>
        </div>
    </script>

    <script>
        App.controller('SpecialTopicController', [
  '$scope', '$state', 'ngDialog', '$http', 'ngTableParams', 'ngTableDataService', 'Notify',
  function ($scope, $state, ngDialog, $http, ngTableParams, ngTableDataService, Notify) {
      'use strict';
      $scope.isLoading = true;
      $scope.tableParams = new ngTableParams({
          page: 1,
          count: 10,
          sorting: {
              DropGroupID: 'desc'     // 初始化排序
          }
      }, {
          getData: function ($defer, params) {
              $scope.isLoading = true;
              var requestParams = {
                  Skip: (params.page() - 1) * params.count(),
                  Take: params.count(),
                  Keywords: $scope.Keywords
              };
              $http.post('/DropGroup/GetDropGroupList', ngTableDataService.getServerSideParams(params.orderBy().toString(), params, requestParams))
                  .success(function (data, status) {
                      console.log(data);
                      if (data.isSuccess) {
                          params.total(data.count);
                          $defer.resolve(data.data);
                      }

                      $scope.isLoading = false;
                  });
          }
      });

      $scope.gogroupheadlist = function (id) {
          $state.go('app.groupheadlist', { "Id": id });
      }


      $scope.edit = function (id) {
          debugger
          $state.go('app.dropGroupEdit', { "id": id });
      }

      $scope.remove = function (index, id) {
          ngDialog.openConfirm({
              template: 'modalDialogId',
              className: 'ngdialog-theme-default'
          }).then(function (value) {
              $http.post("/DropGroup/DelDropGroup", { id: id }).then(function (returnData) {
                  if (returnData.data.isSuccess) {
                      $scope.tableParams.data.splice(index, 1);
                      Notify.alert(returnData.data.msg, { status: 'success', timeout: 1000 });
                  } else {
                      Notify.alert(returnData.data.msg, { status: 'warning', timeout: 1000 });
                  }
              });
          }, function (reason) {
          }
          );
      }
      $scope.updateStatus = function (index, id, state) {
          $http.post("/DropGroup/UpdateDropGroupState", { id: id, state: state }).then(function (returnData) {
              if (returnData.data.isSuccess) {
                  $scope.tableParams.reload();
                  Notify.alert(returnData.data.msg, { status: 'success', timeout: 1000 });
              } else {
                  Notify.alert(returnData.data.msg, { status: 'warning', timeout: 1000 });
              }
          });
      }

  }
        ]);
    </script>
